package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC1432 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int maxDiff(int num) {
            String numStr = String.valueOf(num);
            int max = num, min = num;
            for (int i = 0; i <= 9; i++) {
                for (int j = 0; j <= 9; j++) {
                    if (i == j) continue;
                    String neoStr = numStr.replaceAll(String.valueOf(i), String.valueOf(j));
                    if (neoStr.startsWith("0")) continue;
                    max = Math.max(max, Integer.valueOf(neoStr));
                    min = Math.min(min, Integer.valueOf(neoStr));
                }
            }

            return max - min;
        }
    }

    public void run() {
        System.out.println(new Solution().maxDiff(555));
        System.out.println(new Solution().maxDiff(9));
        System.out.println(new Solution().maxDiff(123456));
        System.out.println(new Solution().maxDiff(10000));
        System.out.println(new Solution().maxDiff(9288));
    }

    public static void main(String[] args) throws Exception {
        LC1432 an = new LC1432();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
